﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CapaPresentacion
{
    public partial class frmPrincipalMenu : Form
    {
        private int childFormNumber = 0;
        public string Idtrabajador = "";
        public string Apellidos = "";
        public string Nombre = "";
        public string Acceso = "";

        private DataGridViewCellStyle HighlightStyle;

        private static frmRegistro_Compras _Instancia;
        public static frmRegistro_Compras GetInstancia()
        {
            if (_Instancia == null)
            {
                _Instancia = new frmRegistro_Compras();
            }
            return _Instancia;
        }


        public frmPrincipalMenu()
        {
            InitializeComponent();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "Ventana " + childFormNumber++;
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "Archivos de texto (*.txt)|*.txt|Todos los archivos (*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "Archivos de texto (*.txt)|*.txt|Todos los archivos (*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
          
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void salirDelSistemaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void ingresoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmIngreso frm = frmIngreso.GetInstancia();
            frm.MdiParent = this;
            frm.Show();
            frm.Idtrabajador = Convert.ToInt32(this.Idtrabajador);
        }

        private void menuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void proveedorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmProveedor frm = new frmProveedor();
            frm.MdiParent = this;
            frm.Show();
        }

        private void registroCmprasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmRegistro_Compras frm = frmRegistro_Compras.GetInstancia();
            frm.MdiParent = this;
            frm.Show();
            frm.Idtrabajador = Convert.ToInt32(this.Idtrabajador);
        }

        private void clientesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmCliente frm = new frmCliente();
            frm.MdiParent = this;
            frm.Show();
        }

        private void registroVentasToolStripMenuItem_Click(object sender, EventArgs e)
        {

            frmRegistro_Ventas frm = frmRegistro_Ventas.GetInstancia();
            frm.MdiParent = this;
            frm.Show();
            frm.Idtrabajador = Convert.ToInt32(this.Idtrabajador);
        }

        private void trabajadoresToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmTrabajador frm = new frmTrabajador();
            frm.MdiParent = this;
            frm.Show();
        }

        private void articulosToolStripMenuItem_Click(object sender, EventArgs e)
        {

            frmArticulo frm = frmArticulo.GetInstancia();
            frm.MdiParent = this;
            frm.Show();
        }

        private void categoriasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmCategoria frm = new FrmCategoria();
            frm.MdiParent = this;
            frm.Show();
        }

        private void presentacionesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmPresentacion frm = new frmPresentacion();
            frm.MdiParent = this;
            frm.Show();
        }

        private void tabla2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmTabla2 frm = new frmTabla2();
            frm.MdiParent = this;
            frm.Show();
        }

        private void tabla8ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmTabla8 frm = new frmTabla8();
            frm.MdiParent = this;
            frm.Show();
        }

        private void tabla10ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmTabla10 frm = new frmTabla10();
            frm.MdiParent = this;
            frm.Show();
        }

        private void planContableToolStripMenuItem_Click(object sender, EventArgs e)
        {

            frmPlancontable frm = new frmPlancontable();
            frm.MdiParent = this;
            frm.Show();
        }
        private void libroDiarioToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmRegistro_LibroDiario frm = frmRegistro_LibroDiario.GetInstancia();
            frm.MdiParent = this;
            frm.Show();
            frm.Idtrabajador = Convert.ToInt32(this.Idtrabajador);

        }


        private void libroCajaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmRegistro_LibroCaja frm = frmRegistro_LibroCaja.GetInstancia();
            frm.MdiParent = this;
            frm.Show();
            frm.Idtrabajador = Convert.ToInt32(this.Idtrabajador);
        }
        private void frmPrincipalMenu_Load(object sender, EventArgs e)
        {
            // TODO: esta línea de código carga datos en la tabla 'dbventasDataSet.spmostrar_Proveedores_Client' Puede moverla o quitarla según sea necesario.
            this.spmostrar_Proveedores_ClientTableAdapter.Fill(this.dbventasDataSet.spmostrar_Proveedores_Client);
            GestionUsuario();




            // Define the highlight style.s
            HighlightStyle = new DataGridViewCellStyle();
            HighlightStyle.ForeColor = Color.Red;
            HighlightStyle.BackColor = Color.Yellow;
            HighlightStyle.Font = new Font(DtGProveedor.Font, FontStyle.Bold);
          



        }



        private void GestionUsuario()
        {
            //controla de accesos

            if (Acceso == "Administrador")
            {
                this.MnuAlmacen.Enabled = true;
                this.MnuCompras.Enabled = true;
                this.MnuVentas.Enabled = true;
                this.MnuMantenimiento.Enabled = true;
                this.MnuConsultas.Enabled = true;
                this.MnuHerramientas.Enabled = true;
            }
            else if (Acceso == "Vendedor")
            {
                this.MnuAlmacen.Enabled = false;
                this.MnuCompras.Enabled = false;
                this.MnuVentas.Enabled = true;
                this.MnuMantenimiento.Enabled = false;
                this.MnuConsultas.Enabled = true;
                this.MnuHerramientas.Enabled = true;
            }
            else if (Acceso == "Almacenero")
            {
                this.MnuAlmacen.Enabled = true;
                this.MnuCompras.Enabled = true;
                this.MnuVentas.Enabled = false;
                this.MnuMantenimiento.Enabled = false;
                this.MnuConsultas.Enabled = true;
                this.MnuHerramientas.Enabled = true;
            }
            else
            {
                this.MnuAlmacen.Enabled = false;
                this.MnuCompras.Enabled = false;
                this.MnuVentas.Enabled = false;
                this.MnuMantenimiento.Enabled = false;
                this.MnuConsultas.Enabled = false;
                this.MnuHerramientas.Enabled = false;
            }
        }

        private void toolStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void plasmToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void bntMinimizar_Click(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Minimized;
        }

        private void btnCerrar_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Estas seguro que desea Salir", "◄ AVISO | Start Tec ►", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
            {
                Application.Exit();
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Maximized)
            {
                WindowState = FormWindowState.Normal;
            }
            else
            {
                WindowState = FormWindowState.Maximized;
            }
            
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void mMToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

   

        private void vIstasToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void personasYOEmpresasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmPersona_Empresa frm = new frmPersona_Empresa();
            frm.MdiParent = this;
            frm.Show();
        }

     

        private void MnuSistema_Click(object sender, EventArgs e)
        {

        }

        private void planillaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmPlanilla frm = new frmPlanilla();
            frm.MdiParent = this;
            frm.Show();
            frm.Idtrabajador = Convert.ToInt32(this.Idtrabajador);
        
        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        // The currently highlighted cell.
        private int HighlightedRowIndex = -1;

        // Set the cell Styles in the given row.
        private void SetRowStyle(DataGridViewRow row, DataGridViewCellStyle style)
        {
            foreach (DataGridViewCell cell in row.Cells)
            {
                cell.Style = style;
            }
        }

        private void Proveedor_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == HighlightedRowIndex) return;

            // Unhighlight the previously highlighted row.
            if (HighlightedRowIndex >= 0)
            {
                SetRowStyle(DtGProveedor.Rows[HighlightedRowIndex], null);
            }

            // Highlight the row holding the mouse.
            HighlightedRowIndex = e.RowIndex;
            if (HighlightedRowIndex >= 0)
            {
                SetRowStyle(DtGProveedor.Rows[HighlightedRowIndex], HighlightStyle);
            }
        }

        private void DtGProveedor_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (HighlightedRowIndex >= 0)
            {
                SetRowStyle(DtGProveedor.Rows[HighlightedRowIndex], null);
                HighlightedRowIndex = -1;
            }
        }

        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        public static string Variable;
        private void dateTimePicker1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == Convert.ToChar(Keys.Enter))
            {
                if (cbOrigen.Text.Equals(Convert.ToString("00 Apertura"))){
                }
                if (cbOrigen.Text.Equals(Convert.ToString("01 Compras")))
                {
                    frmRegistro_Compras frm = frmRegistro_Compras.GetInstancia();
                    frm.MdiParent = this;
                    frm.Show();
                    frm.Idtrabajador = Convert.ToInt32(this.Idtrabajador);
                }
                if (cbOrigen.Text.Equals(Convert.ToString("02 Ventas")))
                {
                    frmRegistro_Ventas frm = new frmRegistro_Ventas();
                    frm.MdiParent = this;
                    frm.Show();
                    frm.Idtrabajador = Convert.ToInt32(this.Idtrabajador);
                }
                if (cbOrigen.Text.Equals(Convert.ToString("03 Caja")))
                {
                    frmRegistro_LibroCaja frm = new frmRegistro_LibroCaja();
                    frm.MdiParent = this;
                    frm.Show();
                    frm.Idtrabajador = Convert.ToInt32(this.Idtrabajador);
                }
                if (cbOrigen.Text.Equals(Convert.ToString("04 Cobranzas")))
                {
                }
                if (cbOrigen.Text.Equals(Convert.ToString("05 Diario")))
                {
                    frmRegistro_LibroDiario frm = new frmRegistro_LibroDiario();
                    frm.MdiParent = this;
                    frm.Show();
                    frm.Idtrabajador = Convert.ToInt32(this.Idtrabajador);
                }
                  if (cbOrigen.Text.Equals(Convert.ToString("06 Planillas")))
                {
                    frmPlanilla frm = new frmPlanilla();
                    frm.MdiParent = this;
                    frm.Show();
                    frm.Idtrabajador = Convert.ToInt32(this.Idtrabajador);
                }
                  if (cbOrigen.Text.Equals(Convert.ToString("07 Automaticos")))
                {
                }
            }
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            frmSubMenu frm =  frmSubMenu.GetInstancia();
            frm.ShowDialog();
            frm.Idtrabajador = Convert.ToInt32(this.Idtrabajador);
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void txtMnhaber_TextChanged(object sender, EventArgs e)
        {

        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {

        }

     


        
       


      
    }
}
